package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsySowingInfo;
import com.ruoyi.ncpsy.service.INcpsySowingInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 播种事件记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/ncpsy/sowcrop")
public class NcpsySowingInfoController extends BaseController
{
    @Autowired
    private INcpsySowingInfoService ncpsySowingInfoService;

    /**
     * 查询播种事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsySowingInfo ncpsySowingInfo)
    {
        startPage();
        List<NcpsySowingInfo> list = ncpsySowingInfoService.selectNcpsySowingInfoList(ncpsySowingInfo);
        return getDataTable(list);
    }

    /**
     * 导出播种事件记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:export')")
    @Log(title = "播种事件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsySowingInfo ncpsySowingInfo)
    {
        List<NcpsySowingInfo> list = ncpsySowingInfoService.selectNcpsySowingInfoList(ncpsySowingInfo);
        ExcelUtil<NcpsySowingInfo> util = new ExcelUtil<NcpsySowingInfo>(NcpsySowingInfo.class);
        util.exportExcel(response, list, "播种事件记录数据");
    }

    /**
     * 获取播种事件记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:query')")
    @GetMapping(value = "/{sowId}")
    public AjaxResult getInfo(@PathVariable("sowId") Long sowId)
    {
        return success(ncpsySowingInfoService.selectNcpsySowingInfoBySowId(sowId));
    }

    /**
     * 新增播种事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:add')")
    @Log(title = "播种事件记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsySowingInfo ncpsySowingInfo)
    {
        return toAjax(ncpsySowingInfoService.insertNcpsySowingInfo(ncpsySowingInfo));
    }

    /**
     * 修改播种事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:edit')")
    @Log(title = "播种事件记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsySowingInfo ncpsySowingInfo)
    {
        return toAjax(ncpsySowingInfoService.updateNcpsySowingInfo(ncpsySowingInfo));
    }

    /**
     * 删除播种事件记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:sowcrop:remove')")
    @Log(title = "播种事件记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sowIds}")
    public AjaxResult remove(@PathVariable Long[] sowIds)
    {
        return toAjax(ncpsySowingInfoService.deleteNcpsySowingInfoBySowIds(sowIds));
    }
}
